<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sx" uri="/struts-dojo-tags" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<sx:head debug="true"/>
<title>菜单树</title>

<script type="text/javascript">
			
			function treeNodeSelected(arg) {
				// alert("id["+arg.source.widgetId+"], name["+ arg.source.title+ "] selected");
				dojo.byId("id").value = arg.source.widgetId;
				dojo.byId("name").value = arg.source.title;
				dojo.byId("url").value = arg.source.value;
				dojo.byId("parentId").value = arg.source.widgetId;
			}
						
			function treeNodeExpanded(arg) {
				// alert("id["+arg.source.widgetId+"], name["+ arg.source.title+ "] expanded");
			}
			
			function treeNodeCollapsed(arg) {
				// alert("id["+arg.source.widgetId+"], name["+ arg.source.title+ "] collapsed");
			}
			
			function save(data, type, request) {
							if(type == "load") {
								dojo.byId("name").value = "";
							}
						}
						
			//			function edit(data, type, request) {
			//				alert("In edit(...)")
										//if(type == "before") {
						//					var id = data.split("_")[1];
						//
						//					var tr = dojo.byId("row_"+id);
						//					var tds = tr.getElementsByTagName("td");
						
			//								dojo.byId("id").value = "<s:property value="id" />";
			//								dojo.byId("name").value = "<s:property value="name" />"
											//dojo.byId("lastName").value = dojo.string.trim(dojo.dom.textContent(tds[1]));
										//}
			//						}
						
			
			
			//dojo.addOnLoad(function() {                
			//    var t = dojo.widget.byId('menuTree');
			//    dojo.event.topic.subscribe(t.eventNames.expand, treeNodeExpanded);                
			//    dojo.event.topic.subscribe(t.eventNames.collapse, treeNodeCollapsed);
				
			//    var s = t.selector;   
						
			
			//});

		
			
		</script>
        
</head>

<body>
<script type="text/javascript">
			// alert('execute dojo.addOnLoad!');
			dojo.addOnLoad(function() {                
			    var t = dojo.widget.byId('menuTree');
			    dojo.event.topic.subscribe(t.eventNames.expand, treeNodeExpanded);                
			    dojo.event.topic.subscribe(t.eventNames.collapse, treeNodeCollapsed);
			    //dojo.event.topic.subscribe("/treeSelected", treeNodeSelected);
			    
			    //dojo.event.topic.subscribe("/save", save);
			    //dojo.event.topic.subscribe("/edit", edit);
			    var s = t.selector;   
		        dojo.event.connect(s, 'select', 'treeNodeSelected');     
		
		    });
</script>





<s:form >
<div style="float:left; margin-right: 50px;" >
<s:url action="menuTree_c" id="menuTreeUrl"></s:url>
<%--<sx:div id="tree" theme="ajax" href="%{menuTreeUrl}" showLoadingText="true" loadingText="Loading..." listenTopics="/refresh"/>--%>

<div id="tree">
  <s:if test="rootNodes.size > 0">
    <s:iterator value="rootNodes" var="rootNode">
      
      
      
      <sx:tree 
		    id="menuTree"
		    rootNode="rootNode"
		    childCollectionProperty="childMenus"
		    nodeIdProperty="id"
		    nodeTitleProperty="name" 
		    value="url">        
       </sx:tree>
      </s:iterator>
  </s:if>
</div>

<s:url action="menuCategoryFormField" id="menuCategoryFormFieldUrl" ></s:url>
<s:url action="menuFormField" id="menuFormFieldUrl" ></s:url>
<%--<sx:a href="%{menuCategoryFormFieldUrl}" targets="inputFields" >添加目录</sx:a>
<sx:a href="%{menuFormFieldUrl}" targets="inputFields">添加菜单</sx:a>--%>





<s:submit action="menutree_category_del" label="删除" value="删除" />
</div>     
</s:form>

<div style="float:left; margin-right: 50px;">
	<%--<s:form  action="menutree_category_edit" >
        编号：<s:property value="category.id"/>
        <s:textfield name="category.id" id="id" cssStyle="display:none" />
        <s:textfield name="category.name" label="名称" id="name"></s:textfield>
        <sx:submit label="保存" notifyTopics="/save" targets="inputFields" />
    </s:form>--%>
    
    <s:form action="menutree_menu_edit">
        <%-- 编号：<s:property value="menu.id" /> --%>
        <s:textfield name="menu.strId" id="id" cssStyle="display:none" />
        <s:textfield name="menu.name" label="名称" id="name"></s:textfield>
        <s:textfield name="menu.url" label="URL" id="url"></s:textfield>
        <s:textfield name="parentId" id="parentId" cssStyle="display:none" ></s:textfield>
        <%--<sx:submit  notifyTopics="/save" targets="tree" label="保存" value="保存"/>--%>
        <s:submit  value="保存" />
    </s:form>
    
<%--	<sx:div id="inputFields" theme="ajax" href="%{menuCategoryFormFieldUrl}" showLoadingText="true" loadingText="Loading..." listenTopics="/refresh"/>
--%>
</div>

</body>
</html>
